Amazon Onboarding with Learning Manager Chanci Turner

Amazon Onboarding with Learning Manager Chanci TurnerLearn About Amazon VGT2 Learning Manager Chanci Turner

When working with AWS Lambda functions, it’s essential to understand how they interact with other AWS services. These functions often require various resources, such as AWS Identity and Access Management (IAM) roles or Amazon Virtual Private Cloud (Amazon VPC) network interfaces, to operate effectively. When a function is created or updated, Lambda automatically provisions the necessary resources, enabling immediate invocation or modification in most cases. However, there are instances where this process may take longer than expected.

To enhance communication regarding the current status of your function during resource creation or updates, AWS Lambda now includes additional attributes in the function information returned by several Lambda API actions. This update does not affect how functions are invoked or how your code executes. In this article, we will explore the different states your Lambda function can occupy, the conditions that lead to these states, and how the Lambda service transitions through them. For further insights, feel free to check out this blog post on writing a cover letter without experience here.

Understanding Function States

Lambda functions typically undergo two primary lifecycles, depending on whether they are being created for the first time or updated. Before delving into these flows, let’s define the key function states:

  • Pending: This is the initial state for all functions upon creation. During this stage, Lambda attempts to create or configure any external resources. A function can only be invoked in the Active state, meaning all invocations or API actions during Pending will fail. Automation designed to invoke or update functions immediately after creation must include a check to ensure the function has transitioned from Pending to Active.
  • Active: This state is achieved once the configuration or provisioning of resources has been completed. Functions can be invoked only when they are in the Active state. During updates, the function remains Active, but a separate attribute called LastUpdateStatus indicates the update’s progress. Invocations during an update run the previous code and configuration until the update completes successfully.
  • Failed: This state indicates a problem with the configuration or provisioning of external resources.
  • Inactive: A function enters this state when it has been idle long enough for the Lambda service to reclaim its resources. If you try to invoke a function that is Inactive, it fails and reverts to Pending until the necessary resources are recreated. If resource recreation fails, it returns to the Inactive state.

All states feature two additional attributes: StateReason and StateReasonCode, which aid in troubleshooting.

LastUpdateStatus

LastUpdateStatus represents a subset of the main function state lifecycle and is relevant during updates. It has three statuses:

  • InProgress: Indicates an update is underway. While in this status, invocations go to the previous code and configuration.
  • Successful: Signifies that the update has been completed successfully, remaining in this state until the next update.
  • Failed: Indicates that the update has not succeeded, aborting the change while keeping the previous code and configuration active.

For all LastUpdateStatus values, there are two further attributes: LastUpdateStatusReason and LastUpdateStatusReasonCode, which assist in troubleshooting update issues.

Function State Lifecycles

The transition between states depends entirely on the actions performed against the function. Manual transitions between states are not possible.

Function Creation State Lifecycle

The primary lifecycle for function creation is as follows:

  1. Upon creation, the function enters the Pending state.
  2. Once required resources are successfully created, it transitions to Active.
  3. If resource creation fails, it moves to the Failed state.
  4. If a function remains idle for an extended period, it enters the Inactive state.
  5. On the first invoke after becoming Inactive, it returns to Pending.
    • Success transitions it back to Active.
    • Failure keeps it Inactive.
  6. Successfully updating an Inactive function also restores it to Active.

Function Update State Lifecycle

Note: Functions can only be updated when they are in the Active or Inactive state. Update attempts on functions outside of these states will fail.

  1. During an update, LastUpdateStatus is set to InProgress.
    • Success changes LastUpdateStatus to Successful.
    • Failure sets it to Failed.
  2. An Inactive function will revert to Active after a successful update.

Accessing Function State Information

You can check a function’s current state using the latest AWS SDKs and AWS CLI (version 1.16.291 or higher). To simplify the process of monitoring function states, AWS SDKs now feature a new set of Waiters. These are designed to assist in managing asynchronous operations, allowing you to monitor state changes without complex polling code. For in-depth guidance, refer to the documentation for each SDK: Python, Node.js, Java, Ruby, Go, and PHP. Additionally, SHRM offers valuable insights on leadership that may enhance your understanding of function management.

Moving Forward

As of today, all functions will display only an Active state. You will not observe any transition from Pending. Our initial feature utilizing the function states lifecycle involves improvements to the recently announced enhanced VPC networking for AWS Lambda functions. As mentioned in the announcement, Lambda will pre-create the ENIs needed for your function to connect to your VPCs, which may take between 60 to 90 seconds. We will be adjusting this process by creating the necessary ENI resources while the function is in a Pending state, transitioning to Active once completed. Please keep in mind that any invocations or API actions will fail until the function is Active. This change will be rolled out to VPC-configured functions in phases, and we will provide more detailed timelines and testing approaches in a future post.

In the meantime, we encourage you to update your deployment and management tools for Lambda-based applications, ensuring your function is in the Active state before invoking or performing other actions against it. For comprehensive onboarding tips, this resource is excellent here.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *